home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
GetDirectory.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
11KB
|
486 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#pragma segment GetDirectory
#include "tickle.h"
#include "tge.h"
#include <DiskInit.h>
#include <OSEvents.h>
#define GETDIRECT_DIALOG 6767
#define GETDIRNEW_DIALOG 6766
#define GETDIRHLP_DIALOG 6765
#define prompt_item 11
#define select_item 12
#define help_item 13
#define new_folder_btn 15 /* New Directory Button */
#define new_folder_name_item 4
#define getInit -1 /* Initialize */
#define sfHookStay 0
static SFReply getDir_Reply;
static char getDir_prompt[256];
/* static short need_check = 0; */
static char save_fName0;
static OSType save_fType;
/* static FILE *gdhfp = NULL; */
#define cm_connect_msg_item 4
void
show_getdir_help(parent)
DialogPtr parent;
{
short itemhit, done;
DialogPtr mydialog;
GrafPtr saveport;
Handle dlogrsrc;
Rect *rect_ptr;
Point mypt;
extern pascal Boolean UniversalFilter();
GetPort(&saveport);
InitCursor();
dlogrsrc = GetResource((ResType)'DLOG', (short)GETDIRHLP_DIALOG);
if (dlogrsrc != NULL) {
LoadResource(dlogrsrc);
rect_ptr = (Rect *) *dlogrsrc;
mypt.v = parent->portRect.bottom - (8 + (rect_ptr->bottom - rect_ptr->top));
mypt.h = parent->portRect.left + 8;
LocalToGlobal(&mypt);
OffsetRect(rect_ptr, (mypt.h - rect_ptr->left), (mypt.v - rect_ptr->top));
}
mydialog = GetNewDialog(GETDIRHLP_DIALOG, NULL, inFront);
if (mydialog == NULL)
{
SysBeep(0);
return;
}
SetPort(mydialog);
TextFont(geneva);
TextSize(9);
for (done=0; ! done; ) {
SetPort(mydialog);
/* FrameButton(mydialog, ok); */
ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemhit);
switch (itemhit) {
case ok:
done = 1;
break;
}
}
DisposDialog(mydialog);
SetPort(saveport);
return;
}
void
getdir_new_folder(parent)
DialogPtr parent;
{
short itemhit, vrefnum, done, create_it = 0, result;
long dirid;
DialogPtr mydialog;
GrafPtr saveport;
Handle dlogrsrc;
Rect *rect_ptr;
Point mypt;
HParamBlockRec pb;
char pascal_name[256];
extern pascal Boolean UniversalFilter();
GetPort(&saveport);
InitCursor();
dlogrsrc = GetResource((ResType)'DLOG', (short)GETDIRNEW_DIALOG);
if (dlogrsrc != NULL)
{
LoadResource(dlogrsrc);
rect_ptr = (Rect *) *dlogrsrc;
mypt.v = parent->portRect.bottom - (8 + (rect_ptr->bottom - rect_ptr->top));
mypt.h = parent->portRect.left + 8;
LocalToGlobal(&mypt);
OffsetRect(rect_ptr, (mypt.h - rect_ptr->left), (mypt.v - rect_ptr->top));
}
mydialog = GetNewDialog(GETDIRNEW_DIALOG, NULL, inFront);
if (mydialog == NULL)
{
SysBeep(0);
return;
}
SelIText(mydialog, new_folder_name_item, 0, 1024);
for (done=0; ! done; )
{
SetPort(mydialog);
FrameButton(mydialog, ok);
ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemhit);
switch (itemhit)
{
case ok:
done = 1; create_it = 1;
break;
case cancel:
done = 1; create_it = 0;
break;
}
}
if (create_it)
{
SFGetDefault(&dirid, &vrefnum);
MyGetText(mydialog, new_folder_name_item, pascal_name);
c2pstr(pascal_name);
pb.fileParam.ioCompletion = 0;
pb.fileParam.ioNamePtr = pascal_name;
pb.fileParam.ioVRefNum = vrefnum;
pb.fileParam.ioDirID = dirid;
result = PBDirCreate( (HParmBlkPtr)&pb, FALSE );
if (result != noErr)
SysBeep(0);
}
DisposDialog(mydialog);
SetPort(saveport);
return;
}
pascal short GetDirHook(item, dialog)
short item;
DialogPtr dialog;
{
int need_check = 0;
switch (item) {
case getInit:
/*
gdhfp = fopen("GETDIR", "a");
if (gdhfp) {
fprintf(gdhfp, "################################################\n");
fprintf(gdhfp, "getInit: dialog x%08lX item %d.\n", dialog, item);
}
*/
need_check = 0;
save_fName0 = getDir_Reply.fName[0];
save_fType = getDir_Reply.fType;
MySetText(dialog, prompt_item, getDir_prompt);
MyHiliteControl(dialog, select_item, 255);
break;
case getOpen: /* Open or DoubleClick with selected file... */
/*
if (gdhfp)
fprintf(gdhfp, "getOpen: dialog x%08lX item %d.\n", dialog, item);
*/
item = sfHookStay;
need_check = 1;
break;
case sfHookOpenFolder: /* Open or DoubleClick with selected folder... */
/*
if (gdhfp)
fprintf(gdhfp, "sfHookOpenFolder: dialog x%08lX item %d.\n", dialog, item);
*/
need_check = 1;
break;
case select_item:
/*
if (gdhfp)
fprintf(gdhfp, "selectItem: dialog x%08lX item %d.\n", dialog, item);
*/
item = getOpen;
break;
case new_folder_btn:
/*
if (gdhfp)
fprintf(gdhfp, "helpItem: dialog x%08lX item %d.\n", dialog, item);
*/
getdir_new_folder(dialog);
item = sfHookRebuildList;
need_check = 1;
break;
case help_item:
/*
if (gdhfp)
fprintf(gdhfp, "helpItem: dialog x%08lX item %d.\n", dialog, item);
*/
show_getdir_help(dialog);
item = sfHookStay;
break;
case getCancel:
/*
if (gdhfp)
fprintf(gdhfp, "getCancel: dialog x%08lX item %d.\n", dialog, item);
*/
break;
case sfHookFolderPopUp:
case getNmList:
case getScroll:
/*
if (gdhfp)
fprintf(gdhfp, "sfHookFolderPopUp,NmList,Scroll: dialog x%08lX item %d.\n", dialog, item);
*/
need_check = 1;
break;
case sfHookNullEvent:
#ifdef NEVER_DEFINED
if (need_check) {
if (gdhfp)
fprintf(gdhfp,
"sfHookNullEvent: dialog x%08lX item %d fName [%d]<%.*s> fType '%-4.4s'[%d].\n",
dialog, item,
getDir_Reply.fName[0], getDir_Reply.fName[0], &getDir_Reply.fName[1],
&getDir_Reply.fType, getDir_Reply.fType);
if (getDir_Reply.fName[0] == '\0' && getDir_Reply.fType == 0)
{
/* NOTHING Selected... */
MyHiliteControl(dialog, select_item, 0);
}
else if (getDir_Reply.fName[0] == '\0')
{
/* DIRECTORY */
MyHiliteControl(dialog, select_item, 0);
}
else
{
/* FILE */
MyHiliteControl(dialog, select_item, 255);
item = sfHookStay;
}
save_fName0 = getDir_Reply.fName[0];
save_fType = getDir_Reply.fType;
need_check = 0;
}
else
{
if (save_fName0 != getDir_Reply.fName[0]
|| save_fType != getDir_Reply.fType)
need_check = 1;
}
#endif
break;
default: /* Key down's are 1000 + ASCII-code */
/*
if (gdhfp)
fprintf(gdhfp, "default: dialog x%08lX item %d.\n", dialog, item);
*/
need_check = 1;
break;
}
if (! need_check)
{
if (save_fName0 != getDir_Reply.fName[0]
|| save_fType != getDir_Reply.fType)
need_check = 1;
}
if (need_check)
{
if (getDir_Reply.fName[0] == '\0' && getDir_Reply.fType == 0)
{
/* NOTHING Selected... */
MyHiliteControl(dialog, select_item, 0);
}
else if (getDir_Reply.fName[0] == '\0')
{
/* DIRECTORY */
MyHiliteControl(dialog, select_item, 0);
}
else
{
/* FILE */
MyHiliteControl(dialog, select_item, 255);
/* item = sfHookStay; */
}
save_fName0 = getDir_Reply.fName[0];
save_fType = getDir_Reply.fType;
need_check = 0;
}
return item;
}
pascal Boolean NoFiles(pb)
FileParam *pb;
{
#pragma unused (pb)
return false;
}
GetFolderPathName(prompt, path_name, volref, dirid)
char *prompt;
char *path_name;
short *volref;
long *dirid;
{
#ifdef TCLAPPL
SFTypeList mytypes;
Point mypoint;
int len;
WindowPtr myWindow;
strcpy(getDir_prompt, prompt);
myWindow = FrontWindow();
if (WPeek->windowKind == tgeWKind)
tge_activate(myWindow, 0);
/* gdhfp = (FILE *)0; */
mypoint.h = mypoint.v = 75;
SFPGetFile(mypoint, "\p", NoFiles, -1, mytypes, GetDirHook,
&getDir_Reply, GETDIRECT_DIALOG, (ModalFilterProcPtr)0);
/*
if (gdhfp) {
fclose(gdhfp);
gdhfp = (FILE *)0;
}
*/
if (getDir_Reply.good) {
/*
Feedback("GOOD: fName '%.*s' fType '%-4.4s'[%ld] vRef %d V %d D %ld ",
getDir_Reply.fName[0], &getDir_Reply.fName[1],
&getDir_Reply.fType, getDir_Reply.fType,
getDir_Reply.vRefNum, WDVolRef(getDir_Reply.vRefNum), WDDirID(getDir_Reply.vRefNum));
*/
if (getDir_Reply.fName[0] != '\0'/*getDir_Reply.fType == 0*/) {
*volref = WDVolRef(getDir_Reply.vRefNum);
*dirid = WDDirID(getDir_Reply.vRefNum);
pathname(path_name, getDir_Reply.vRefNum);
}
else {
dirpathname(path_name, getDir_Reply.vRefNum, getDir_Reply.fType/*cpb.dirInfo.ioDrParID*/);
*volref = getDir_Reply.vRefNum;
*dirid = getDir_Reply.fType/*cpb.dirInfo.ioDrParID*/;
}
len = strlen(path_name);
if (path_name[len - 1] == ':')
path_name[len - 1] = '\0'; /* Drop Colon */
return 1;
}
else
return 0;
#else
#pragma unused (prompt, path_name, volref, dirid)
return 0;
#endif
}
#ifdef NEVER_DEFINED
#define getInit -1 /* Initialize */
#define getMenu 102 /* Folder Menu Mouse */
#define getFolder 103 /* Open Folder */
#define getUseDir 11 /* Use This Directory Button */
pascal short DHook(item, dialog)
short item;
DialogPtr dialog;
{
#pragma unused (dialog)
if (item == getUseDir)
return getOpen;
return item;
}
pascal Boolean NoFiles(pb)
FileParam *pb;
{
#pragma unused (pb)
return true;
}
GetFolderPathName(path_name, volref, dirid)
char *path_name;
short *volref;
long *dirid;
{
SFReply myreply;
SFTypeList mytypes;
CInfoPBRec cpb;
Point mypoint;
int len;
WindowPtr myWindow;
myWindow = FrontWindow();
if (WPeek->windowKind == tgeWKind)
tge_activate(myWindow, 0);
mypoint.h = mypoint.v = 75;
SFPGetFile(mypoint, "\p", NoFiles, -1, mytypes, DHook,
&myreply, get_folder_dialog, (ModalFilterProcPtr)0);
if (myreply.good) {
if (myreply.fType == 0) {
*volref = WDVolRef(myreply.vRefNum);
*dirid = WDDirID(myreply.vRefNum);
pathname(path_name, myreply.vRefNum);
}
else {
cpb.dirInfo.ioVRefNum = myreply.vRefNum;
cpb.dirInfo.ioNamePtr = NULL;
cpb.dirInfo.ioDrDirID = myreply.fType;
cpb.dirInfo.ioFDirIndex = -1;
PBGetCatInfo(&cpb, FALSE);
dirpathname(path_name, myreply.vRefNum, cpb.dirInfo.ioDrParID);
*volref = myreply.vRefNum;
*dirid = cpb.dirInfo.ioDrParID;
}
len = strlen(path_name);
if (path_name[len - 1] == ':')
path_name[len - 1] = '\0'; /* Drop Colon */
return 1;
}
else
return 0;
}
#endif